<?php
/**
 * 招聘信息编辑页面
 *
 * @author Alen
 * @since 1.0.0 2013-10-5 sutroon
 */
class JoinUs_EditAction extends AdmincpAction {
    //put your code here
    public function index(){
        
        // 获取主键编号
        $id=request_string('id');
        // 读取数据
        if($id){
            
            $this->dm->tablename='tinfojob';
            $data=$this->dm->select_one_row('','SerialNo=\''.$id.'\'');
            if(!$data) redirect('招聘信息不存在','?m=JoinUs_List');
        }else{
            $data=array('Name'=>'','Wages'=>'');
        }       
        
        // 设置页面信息,如页面标题,meta信息等
        $this->set_page_info($data['Name']);
        
        // 构建表单内容
        $this->uig->begin_form();
        $this->uig->add_textfield('职位名称','title',$data['Name'],'职位名称长度不超过30个字符');
        $this->uig->add_editorfield('内容','content',$data['Wages']);
        $this->uig->add_controlfield();
        $this->uig->add_hiddenfield(array('action'=>'save'));
        $this->uig->end_form();
        $this->assign('form', $this->uig->get_text());    
        // 显示模板
        $this->display();
    }
    public function save(){
        
        $this->dm->tablename='tinfojob';
        $this->dm->add_param('Title',request_string('title'),'标题不能为空');
        $this->dm->add_param('Content',request_string('content'),'内容不能为空');
        if($this->dm->has_error())redirect($this->dm->get_error());
        $id=request_numeric('id');
        if($id>0){
            $this->dm->update('id='+$id);
        }else{
            $this->dm->insert();
        }
        if($this->dm->has_error()){
            redirect($this->dm->get_error());
        }
        redirect('保存成功','?m=JoinUs_List');
    }
}

?>
